package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.ReservationCountAndTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();

        int count=reservationService.getCancelledReservationCount(userId);
        System.out.println(userId);
        return R.ok(count);
    }
    //小程序端新增预约
    @PostMapping
    public AjaxResult addReservation(@RequestBody Reservation reservation) {
        reservationService.insertReservation(reservation);
        return  AjaxResult.success();
    }
    //小程序端预约信息分页查询
    @GetMapping("/page")
  public R<TableDataInfo<Reservation>> page(@RequestParam( defaultValue = "1") Integer pageNum,
                               @RequestParam( defaultValue = "10") Integer pageSize,
                               @RequestParam(required = false) Integer status){
        TableDataInfo<Reservation> tableDataInfo = reservationService.numberPage(pageNum,pageSize,status);
        return R.ok(tableDataInfo);
    }
    //小程序端取消预约
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@ApiParam("预约ID") @PathVariable("id") Long id) {
        reservationService.deleteReservationById(id);;
        return AjaxResult.success();
    }
    //小程序查询每个时间段剩余预约次数
    @GetMapping("/countByTime")
    public R<List<ReservationCountAndTimeVo>> selectCountByTime( long time) {
        List<ReservationCountAndTimeVo> reservationCountAndTimeVo =reservationService.selectCountByTime(time);

        return R.ok(reservationCountAndTimeVo);
    }

}